<?php

namespace library\common\wechat_msg;

use library\tencent\wechat\admin_wechat\SendTemplateMessage;

/**
 * Created by PhpStorm.
 * User: yxs
 * Date: 2017/8/16
 * Time: 12:36
 */
class send_msg
{
    // <editor-fold defaultstate="collapsed" desc="用户下单成功，通知配送员配送">
    public static function dispatching_msg($oauths, $order, $goods)
    {
        if (!empty($oauths) && !empty($order)) {
            foreach ($oauths as $o) {
                $msg_data = array(
                    'touser' => $o,
                    'keyword1' => implode(",", array_unique($goods)),
                    'keyword2' => date('Y-m-d H:i:s', time()),
                    'keyword3' => "{$order['o_province']}{$order['o_city']}{$order['o_district']}{$order['o_address']}",
                    'keyword4' => "{$order['o_name']}  {$order['o_mobile']}",
                    'keyword5' => $order["order_amount"] . '元'
                );
                $order_id = $order['id'];
                $url = "http://wm.qzzm.com/wechat.php/delivery/Order/detail?order_id={$order_id}&ps=1";
                $result = SendTemplateMessage::send_message("OPENTM208036452", $msg_data, $url);

                // file_put_contents('./text1.txt', $result . '<br/>', FILE_APPEND);
            }
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="支付成功">
    public static function pay_suc_msg($openid, $order)
    {
        if (!empty($openid) && !empty($order)) {
            $msg_data = array(
                'touser' => $openid,
                'keyword1' => $order["order_sn"],
                'keyword2' => "支付成功",
                'keyword3' => date('Y-m-d H:i:s', time()),
                'keyword4' => "外卖",
                'keyword5' => $order["pay_amount"] . '元'
            );
            SendTemplateMessage::send_message("OPENTM204987032", $msg_data);
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="配送员配送通知">
    public static function ps_msg($openid, $order, $delivery_account, $goods)
    {
        if (!empty($openid) && !empty($order) && !empty($delivery_account)) {
            $msg_data = array(
                'touser' => $openid,
                'keyword1' => implode(",", array_unique($goods)),
                'keyword2' => $order["order_sn"],
                'keyword3' => $delivery_account["name"],
                'keyword4' => $delivery_account["mobile"]
            );
            $order_id = $order['id'];
            $url = "http://wm.qzzm.com/wechat.php/order/Order/detail?order_id={$order_id}";
            SendTemplateMessage::send_message("OPENTM406590003", $msg_data, $url);
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="用户收货通知">
    public static function user_take_msg($openid, $order, $goods)
    {
        if (!empty($openid) && !empty($order)) {
            $msg_data = array(
                'touser' => $openid,
                'keyword1' => $order["order_sn"],
                'keyword2' => implode(",", array_unique($goods)),
                'keyword3' => date('Y-m-d H:i:s', $order["order_time"]),
                'keyword4' => date('Y-m-d H:i:s', $order["ps_time"]),
                'keyword5' => date('Y-m-d H:i:s', time())
            );

            $order_id = $order["id"];
            $url = "http://wm.qzzm.com/wechat.php/delivery/Order/detail?order_id={$order_id}";
            SendTemplateMessage::send_message("OPENTM202314085", $msg_data, $url);
        }
    }
    // </editor-fold>
}